package com.dwms.controller;

import com.dwms.entity.PageResponse;
import com.dwms.entity.QueryRequest;
import com.dwms.entity.Request;
import com.dwms.entity.Result;
import com.dwms.entity.system.dept.request.DeptQueryRequest;
import com.dwms.entity.system.dept.request.DeptRequest;
import com.dwms.entity.system.dept.response.DeptResponse;
import com.dwms.feign.system.DeptFeignClient;

import com.dwms.utils.WebUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: DeptMapper
 * @Description: Dept
 * @Create 2022/03/05 20:46
 * @Author WH
 * @Since 2.0.0
**/
@Tag(name = "部门管理")
@RestController(value = "DeptController")
@RequestMapping(value = "/system/dept")
@RequiredArgsConstructor
public class DeptController {

    private final HttpServletRequest request;
    private final DeptFeignClient deptFeignClient;

    @Operation(summary = "新增部门")
    @PostMapping("/save")
    public Result save(@RequestBody DeptRequest deptRequest) {
        WebUtil.getAdminRequest(request,deptRequest);
        return deptFeignClient.save(deptRequest);
    }

    @Operation(summary = "修改部门")
    @PostMapping("/update")
    public Result update(@RequestBody DeptRequest deptRequest) {
        WebUtil.getAdminRequest(request,deptRequest);
        return deptFeignClient.update(deptRequest);
    }

    @Operation(summary = "分页查询部门")
    @PostMapping("/findPage")
    public Result<PageResponse<DeptResponse>> findPage(@RequestBody DeptQueryRequest query) {
        WebUtil.getAdminRequest(request,query);
        return deptFeignClient.findPage(query);
    }

    @Operation(summary = "根据ID查询部门")
    @PostMapping("/findById")
    public Result findById(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return deptFeignClient.findById(query);
    }

    @Operation(summary = "删除部门")
    @PostMapping("/delete")
    public Result delete(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return deptFeignClient.delete(query);
    }

    @Operation(summary = "查询部门树形结构")
    @PostMapping("/findTree")
    public Result<List<DeptResponse>> findTree() {
        Request requestVO = new Request();
        WebUtil.getAdminRequest(request, requestVO);
        return deptFeignClient.findTree(requestVO);
    }

    @Operation(summary = "修改状态")
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody QueryRequest query) {
        WebUtil.getAdminRequest(request,query);
        return deptFeignClient.updateStatus(query);
    }
}
